package leetcode.thread;

import java.util.concurrent.atomic.AtomicInteger;

public class Foo {

    private AtomicInteger atomicInteger = new AtomicInteger(0);

    public Foo() {

    }

    public void first(Runnable printFirst) throws InterruptedException {
        printFirst.run();
        atomicInteger.incrementAndGet();
    }

    public void second(Runnable printSecond) throws InterruptedException {
        while (atomicInteger.get() != 1){

        }
        printSecond.run();
        atomicInteger.incrementAndGet();
    }

    public void third(Runnable printThird) throws InterruptedException {
        while (atomicInteger.get() != 2) {

        }
        printThird.run();
    }
}
